package com.gxa.teax.sso.controller;

import com.gxa.teax.cores.utils.JsonResult;
import com.gxa.teax.sso.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.Pattern;
import java.util.Map;

/**
 * @program: IntelliJ IDEA
 * @description:
 * @author: Mr.Wang
 * @create: 2022-07-06 15:11
 **/
@RestController
@Validated
@Api(tags = "注册短信发送接口")
@RequestMapping("/sms")
public class SmsController {
    @Autowired
    SmsService smsService;

    @PostMapping("sendSms")
    @ApiOperation("短信发送")
    public Map<String ,Object> sendSms(@RequestParam @Pattern(regexp = "^((13[0-9])|(15[^4,\\D])|(14[57])|(17[0])|(17[7])|(18[0,0-9]))\\d{8}$",message = "手机格式不正确")String phone) throws Exception {
        smsService.sendLoginSms(phone);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("验证码已发送");
        return jsonResult.getMap();
    }
}
